package com.woniuxy.controllers;


import com.woniuxy.entitys.RestPOJO;
import com.woniuxy.entitys.Service;
import com.woniuxy.entitys.Users;
import com.woniuxy.services.ServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "服务管理接口")


public class ServiceManagementController {
    @Autowired
    private ServiceService serviceService;


    @ApiOperation(
            value = "根据年份和客户id分组查询",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )

    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="year",value="年份",required=false),
            @ApiImplicitParam(paramType="query",name="com_id",value="公司id",required=false),

    })
    //根据年份和客户id分组查询
    @GetMapping("/serve/count")
    public  RestPOJO getServeCount(String year ,Integer com_id){
        System.out.println(year);
        List<Map<String,Object>> service = serviceService.getServeCount(year,com_id);
        RestPOJO restPOJO = new RestPOJO();
        if (service != null) {
            restPOJO.setStatus(1000);
            restPOJO.setMessage("查询成功");
            restPOJO.setData(service);
        } else {
            restPOJO.setStatus(1001);
            restPOJO.setMessage("查询失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "根据id查询服务",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )

    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path",name="id",value="当前用户id",required=false),

    })

    //根据id查询
    @GetMapping("/selById/{id}")
    public RestPOJO selectById(@PathVariable int id) {
        RestPOJO restPOJO = new RestPOJO();
        Service service = serviceService.selectByPrimaryKey(id);
        if (service != null) {
            restPOJO.setStatus(1000);
            restPOJO.setMessage("查询成功");
            restPOJO.setData(service);
        } else {
            restPOJO.setStatus(1001);
            restPOJO.setMessage("查询失败");
        }
        return restPOJO;
    }
    //分配服务
    @ApiOperation(
            value = "分配服务添加服务信息",
            httpMethod = "PUT",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PutMapping("/ass")
    public RestPOJO distribution(@RequestBody Service service) {
        RestPOJO restPOJO = new RestPOJO();
        int i = serviceService.updateByPrimaryKey(service);
        if (i > 0) {
            restPOJO.setStatus(1000);
            restPOJO.setMessage("添加成功");
        } else {
            restPOJO.setStatus(1001);
            restPOJO.setMessage("添加失败");
        }
        return restPOJO;
    }

}
